<template>
	<public-view :isTabbar="true" navType="findCar">
		<view class="content flex f-d-c a-i-c">
			<view class="car-list">
				<block v-for="(item, index) in list" :key="index">
					<car-box @click="goToInfo(item)" :data="item"></car-box>
				</block>
			</view>
			<view class="f-s-24 color-333 daodi">
				到底了～
			</view>
		</view>
	</public-view>
	
</template>

<script>
	import carBox from "@/components/myComponents/carBox.vue"
	import {goTo} from "@/nav.js"
	export default {
		components:{
			"car-box":carBox
		},
		data() {
			return {
				page:1,
				address:{},
				list:[],
				type:1
			};
		},
		watch:{
			"$store.state.find_car_tab":{
				handler(newVal,oldVal) {
					this.page = 1
					this.type = newVal
					this.list = []
					this.getFindeCarList()
				},
			},
			"$store.state.nav_address":{
				handler(newVal,oldVal) {
					this.page = 1
					this.list = []
					this.address = newVal
					this.getFindeCarList()
				},
				deep:true
			}
		},
		onLoad() {
			// this.getFindeCarList()
		},
		onShow() {
			this.address = this.$store.state.nav_address
			this.getFindeCarList()
			this.$setNotice()
		},
		onReachBottom() {
			this.page++
			this.getFindeCarList()
		},
		onPullDownRefresh() {
			this.page = 1
			this.list = []
			this.getFindeCarList()
		},
		methods:{
			getFindeCarList(type=1){
				let that = this
				let area_id = this.$store.state.nav_address.area.id || ""
				if(!!!area_id){
					return
				}
				that.util.postRequest({
					url:"v1/content/transport",
					data:{
						type:that.type,
						page:that.page,
						rows:10,
						first_area_id:area_id
					}
				}).then(res=>{
					console.log(res)
					uni.stopPullDownRefresh()
					if(that.page === 1){
						that.list = res.data.data
					}else{
						if(res.data.data.length>0){
							that.list = that.list.concat(res.data.data)
						}else{
							that.page--
						}
					}
				}).catch(e=>{
					uni.stopPullDownRefresh()
				})
			},
			goToInfo(e){
				goTo({url:"/pages/findCar/info?id="+e.id})
			},
			callPhone(){
				uni.makePhoneCall({
					phoneNumber:"18023491122"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.daodi{
		margin-top: 80upx;
	}
	.car-list{
		width: 100%;
		padding: 0 28upx;
	}
	.content{
		padding-top: 64upx;
		width: 750upx;
	}

</style>
